//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.middlegroup.subjectpay.service.ucfpay;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;

public class CaUtils {
    public CaUtils() {
    }

    public static String getX509Key(String path) throws IOException, IllegalArgumentException {
        if(null != path && !"".equals(path)) {
            FileInputStream in = null;

            String var4;
            try {
                in = new FileInputStream(path);
                CertificateFactory e = CertificateFactory.getInstance("X.509");
                Certificate cer = e.generateCertificate(in);
                var4 = Base64.encodeBase64String(cer.getPublicKey().getEncoded());
            } catch (Exception var8) {
                throw new IllegalArgumentException("Failed to get X509 key", var8);
            } finally {
                if(null != in) {
                    in.close();
                }

            }

            return var4;
        } else {
            return "";
        }
    }

    public static String getPKCS8Key(String path, String pwd, String aliaesName) throws IOException, IllegalArgumentException {
        if(null != path && !"".equals(path)) {
            FileInputStream fis = null;

            String var6;
            try {
                fis = new FileInputStream(path);
                KeyStore e = KeyStore.getInstance("PKCS8", "RSA");
                e.load(fis, pwd.toCharArray());
                PrivateKey priKey = (PrivateKey)((PrivateKey)e.getKey(aliaesName, (char[])null));
                var6 = Base64.encodeBase64String(priKey.getEncoded());
            } catch (Exception var10) {
                throw new IllegalArgumentException("Failed to get PKCS8 key", var10);
            } finally {
                if(null != fis) {
                    fis.close();
                }

            }

            return var6;
        } else {
            return "";
        }
    }

    public static void main(String[] args) {
        try {
            System.out.println(getX509Key("D:/M200000390.der"));
        } catch (IllegalArgumentException var2) {
            var2.printStackTrace();
        } catch (IOException var3) {
            var3.printStackTrace();
        }

    }
}
